// CrossPlatformCondition.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "WnEvent.h"
#include <deque>
#include <Windows.h>
#include <iostream>
using namespace std;

#include <boost/thread.hpp>
using namespace boost;

deque<int> g_queue;
CWnEvent g_event;

void func1()
{

  while(1)
  {
    this_thread::sleep(posix_time::seconds(5));
    g_event.wait();
    while(!g_queue.empty())
    {
      int i = g_queue.front();
      g_queue.pop_front();
      cout << GetCurrentThreadId() << " " << i << endl;
    }
  }
}

void func2()
{
  this_thread::sleep(posix_time::seconds(1));
  int i = 0;
  while(1)
  {
    ++i;
    g_queue.push_back(i);
    g_event.notify_all();
    this_thread::sleep(posix_time::millisec(100));
  }
}

int _tmain(int argc, _TCHAR* argv[])
{
  thread t1(func1);
   thread t2(func1);
  thread t3(func2);

  t1.join();
  //t2.join();
  //t3.join();

  return 0;
}